<template>
    <view v-if="load_complete" :style="'background:url(' + scoring_info.wechat_judge_background + ') no-repeat;background-size:  100% 100%; width: 100%;height: 100%;'">
        <!-- 未注册 -->
        <view v-if="!judge_info.id" style="display: flex; align-items: center; justify-content: center; height: 100%; width: 100%; flex-direction: column">
            <view style="" class="reg-title">评委通道</view>
            <view class="reg-input">
                <input @input="inputChange" name="regcode" data-name="regcode" :data-required="true" placeholder="请输入注册码，注册" type="text" :value="input_data_regcode" />
            </view>
            <view @tap="regcodeSubmit" style="" class="reg-btn">进入评分</view>
        </view>
        <!-- 已注册 -->
        <view v-else-if="" style="height: 97%; padding-bottom: 3%">
            <view class="judge-title">你好，{{ judge_info.name }}</view>
            <view class="judge-search">
                <input @input="inputChange" name="keyword" data-name="keyword" :data-required="true" placeholder="通过姓名/参赛编号搜索" type="text" value="" />
                <button class="judge-search-btn iconfont icon-sousuo"></button>
            </view>
            <view class="player-list">
                <view class="player-one" @tap="doScore" :data-id="item.id" v-for="(item, index) in player_list" :key="index">
                    <view class="player-photo">
                        <view v-if="item.sort" class="team_name">编号：{{ item.sort }}</view>
                        <image class="user_img" :lazyLoad="true" mode="aspectFill" :src="item.avatar"></image>
                    </view>

                    <view class="player-info">
                        <text style="float: left; margin-left: 5px" v-if="item.name">姓名：{{ item.name }}</text>
                        <text style="float: right; margin-right: 5px" v-if="item.total_score">得分：{{ item.total_score }}</text>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
var app = getApp();
// wxz_wzbagent/pages/live_scoring/judge.js
export default {
    data() {
        return {
            scoring_id: '',
            scoring_info: [],

            judge_info: {
                id: '',
                name: ''
            },

            openid: '',
            player_list: [],
            load_complete: 0,
            input_data_regcode: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.onLoadClone3389(options);
    },
    onPullDownRefresh: function () {
        this.refresh();
        uni.stopPullDownRefresh();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        /**
         * 生命周期函数--监听页面加载
         */
        onLoadClone3389(options) {
            uni.hideHomeButton();
            const that = this;
            uni.login({
                success: function (res) {
                    app.globalData.util.request({
                        url: 'live_scoring&r=login',

                        data: {
                            scoring_id: options.scoring_id,
                            code: res.code
                        },

                        cachetime: '0',
                        showLoading: 0,

                        success: function (t) {
                            that.setData({
                                scoring_id: options.scoring_id,
                                openid: t.data.data.openid,
                                judge_info: t.data.data.judge_info,
                                player_list: t.data.data.player_list,
                                scoring_info: t.data.data.scoring_info,
                                load_complete: 1
                            });
                            uni.setNavigationBarTitle({
                                title: t.data.data.scoring_info.screen_title
                            });
                        }
                    });
                }
            });
        },

        inputChange(t) {
            var name = 'input_data_' + t.currentTarget.dataset.name;
            this.input_data_t.currentTarget.dataset.name = t.detail.value;
        },

        doScore(t) {
            var id = t.currentTarget.dataset.id;
            var that = this;
            uni.navigateTo({
                url: './doscore?id=' + id + '&openid=' + that.openid
            });
        },

        regcodeSubmit() {
            const that = this;
            const regcode = that.input_data_regcode;
            app.globalData.util.request({
                url: 'live_scoring&r=checkRegcode',
                data: {
                    scoring_id: that.scoring_id,
                    regcode: regcode,
                    openid: that.openid
                },
                cachetime: '0',
                showLoading: 0,
                success: function (t) {
                    that.setData({
                        judge_info: t.data.data.judge_info,
                        player_list: t.data.data.player_list,
                        scoring_info: t.data.data.scoring_info
                    });
                }
            });
        },

        refresh() {
            this.onLoadClone3389(this.options, {});
        }
    }
};
</script>
<style>
@import './judge.css';
</style>
